#include "CodeContainer.hpp"
#include "IdentTable.hpp"

#include <iostream>
using namespace std;

CodeContainer::CodeContainer() {
}

CodeContainer::~CodeContainer() {
	int size = tabInstructions.size();
	for (int i = 0; i < size; i++){
		delete tabInstructions[i];
	}

	tabInstructions.clear();
}

void CodeContainer::add(Instruction* instruction) {
	if(instruction !=NULL){
		tabInstructions.push_back(instruction);
	}
}

int CodeContainer::size(){
	return tabInstructions.size();
}


void CodeContainer::add(CodeContainer* code) {
	int currentSize = this->size();
	for (int i = 0; i < code->size(); i++)
	{
		tabInstructions.push_back(code->getInstruction(i));
	}
}

Instruction* CodeContainer::getInstruction(int i) {
	return tabInstructions[i];
}

void CodeContainer::show(IdentTable * identTable) {
	Instruction* inst;
	Operand* op1;
	Operand* op2;
	Operand* op3;
	
	cout << "** Code (" << "" << ")" << endl;
//	cout << "nombre d'instructions dans ce conteneur de code = " << tabInstructions.size() << endl;
	for(int i = 0 ; i < tabInstructions.size(); i++) {
		tabInstructions[i]->show(identTable);
	}
}

